<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* 实训
*/
class Shixun extends User_Controller {

	function index(){
		$data = json_decode(file_get_contents("http://123.206.137.187:804/HandlerData.ashx?action=GetZhangtaoInfo"),true);
		$shixun_data = $shixun_list = array();
		if(!empty($data['rows']) && count($data['rows']) > 0){
			$this->load->model("Shixuns");
			$ids = '';
			$this->load->model("Subjects");
			foreach ($data['rows'] as $key => $value) {
				$value['effective_day'] = get_effective_time($this->user_data['id'], $value['Id'], 5);
				if($value['effective_day'] > 0){
					$value['order_status'] = 2;
				}else{
					$value['order_status'] = $this->Subjects->check_subject_buystatus($value['Id'], 5);
				}
				$shixun_list[$value['Id']] = $value;
				if($key == 0){
					$ids .= "'" . $value['Id'] . "'";
				}else{
					$ids .= ",'" . $value['Id'] . "'";
				}
			}
			$pack_list = $this->Shixuns->get_sx_packages($ids);
			if($pack_list){
				foreach ($pack_list as $k => $v) {
					$shixun_list[$v['sx_id']]['status'] = $v['status'];
					$shixun_list[$v['sx_id']]['pack_id'] = $v['id'];
					$shixun_data[] = $shixun_list[$v['sx_id']];
				}
			}
		}
		$this->smarty->assign("menu", 'shixun');
		$this->smarty->assign("shixun_list", $shixun_list);
		$this->smarty->display("shixun/tlist.html");
	}

	function check_shixun_order(){
		if(empty($this->user_data)){
			echo 9;exit;
		}
		$post_data = $this->input->post();
		$this->load->model("Order_model");
		$order_info = $this->Order_model->get_sx_order($post_data['sx_id'], $this->user_data['id'], $this->school_id);
		$buy_status = 0;
		if(!empty($order_info)){
			$buy_status = 1;
		}
		echo $buy_status;
	}

	function create_sx_order(){
		if(empty($this->user_data)){
			echo 9;exit;
		}
		$post_data = $this->input->post();
		if(empty($post_data['sx_id'])){
			echo 0;
		}else{
			$this->load->model('Order_model');
			$settle_id = $this->Order_model->buy_now($this->user_data['id'],$post_data['sx_id'],$post_data['sx_id'],5);
			echo $settle_id;
		}
	}
}
